package top.jiangqiang.qianyi.common.filter;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.filter.OrderedFilter;
import top.jiangqiang.qianyi.common.constants.GlobalConstants;

import java.util.List;

/**
 * 实现此过滤器之后，只需要注入容器即可生效，免去其余配置，并且可以精确控制请求路径
 * includePatterns为空，则拦截所有路径
 * order默认为0，优先级越小越高
 * excludePatterns优先级比includePatterns更高
 */
@Getter
@Slf4j
public abstract class AbstractPathMatchingOrderedFilter extends AbstractPathMatchingFilter implements OrderedFilter {

    /**
     * 优先级越小越高
     */
    private int order = GlobalConstants.FilterConstants.DEFAULT_FILTER_ORDER;

    /**
     * 拦截所有路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter() {
        super();
    }

    /**
     * @param includePatterns 拦截指定路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter(String... includePatterns) {
        super(includePatterns);
    }

    /**
     * @param includePattern  拦截指定路径，使用springboot3.0默认的路径解析规则
     * @param order           优先级顺序
     * @param excludePatterns 排除指定路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter(String includePattern, int order, String... excludePatterns) {
        super(includePattern, excludePatterns);
        this.order = order;
    }

    /**
     * @param includePatterns 拦截指定路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter(List<String> includePatterns) {
        super(includePatterns);
    }

    /**
     * @param includePatterns 拦截指定路径，使用springboot3.0默认的路径解析规则
     * @param order           优先级顺序
     * @param excludePatterns 排除指定路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter(List<String> includePatterns, int order, String... excludePatterns) {
        super(includePatterns, excludePatterns);
        this.order = order;
    }

    /**
     * @param includePatterns 拦截指定路径，使用springboot3.0默认的路径解析规则
     * @param order           优先级顺序
     * @param excludePatterns 排除指定路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter(List<String> includePatterns, int order, List<String> excludePatterns) {
        super(includePatterns, excludePatterns);
        this.order = order;
    }

    /**
     * 拦截除了被排除的路径以外所有路径
     *
     * @param order           优先级顺序
     * @param excludePatterns 排除指定路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter(int order, String... excludePatterns) {
        super(excludePatterns);
        this.order = order;
    }

    /**
     * 拦截除了被排除的路径以外所有路径
     *
     * @param order           优先级顺序
     * @param excludePatterns 排除指定路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter(int order, List<String> excludePatterns) {
        super(excludePatterns);
        this.order = order;
    }

    /**
     * @param includePatterns 拦截指定路径，使用springboot3.0默认的路径解析规则
     * @param excludePatterns 排除指定路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter(List<String> includePatterns, List<String> excludePatterns) {
        super(includePatterns, excludePatterns);
    }

    /**
     * @param includePatterns 拦截指定路径，使用springboot3.0默认的路径解析规则
     * @param excludePatterns 排除指定路径，使用springboot3.0默认的路径解析规则
     */
    public AbstractPathMatchingOrderedFilter(List<String> includePatterns, String... excludePatterns) {
        super(includePatterns, excludePatterns);
    }

}
